package com.demo1.dao;

import com.demo1.entity.User;

import java.util.List;

/**
 * @author wzm
 * @create 2023-11-07 11:48
 * project_name:web2310
 * @Description
 */
//定义User数据访问的类 将跟User相关增删改查的方法
public class UserDao extends BaseDao {

    //定义一个根据用户名和密码查询返回一个用户的方法
    public User selectByNameAndPassWord(User user){
        //查询数据库中的用户
        return  selectbyOne(
                User.class,
                "select * from tb_user where username = ? and password = ?",
                user.getUsername(),
                user.getPassword()
        );

    }


    //根据用户名查询用户的方法
    public User selectByUserName(String username) {
        //根据用户名查询一个对象
        return selectbyOne(User.class,"select * from tb_user where username = ?",username);
    }

    //新增用户的方法
    public void add(User user) {
        update("insert into tb_user(username,password) values(?,?)", user.getUsername(),user.getPassword());
    }

    //模糊所有的方法
    public List<User> selectByLikeName(String likeName) {
       //return selectForList(User.class,"select * from tb_user where username like ?","%"+likeName+"%");
       return selectForList(User.class,"select * from tb_user where username like concat('%',?,'%')",likeName);
    }
}


